// ============================== 导入依赖 ============================== //

import API from './API'

// ============================== 导出异步调用 ============================== //

export default {
  // —————————————————————————————— 信息 —————————————————————————————— //

  async remoteInfo({ state: { infoParam } }) {
    const tempList = await API.getTemp(infoParam)
    const organList = await API.getOrgan(infoParam)
    const reserveList = await API.getReserve(infoParam)
    const arriveList = await API.getArrive(infoParam)

    return {
      temp: transType(tempList),
      organ: transType(organList),
      trend: transTrend(reserveList, arriveList),
    }
  },
}

// ============================== 转换方法 ============================== //

const transType = (arr) => {
  return {
    xData: arr.map((item) => item.name),
    dataList: arr.map((item) => item.quantity),
  }
}

const transTrend = (arr1, arr2) => {
  return {
    dataListMulti: [arr1.map((item) => item.totalQuantity), arr2.map((item) => item.totalQuantity)],
  }
}
